﻿using Abp;
using Abp.Configuration;
using Mt.Site.Application.UiCustomization.Dto;
using System.Threading.Tasks;

namespace Mt.Site.Application.UiCustomization
{
    public class ThemeDefaultUiCustomizer : IUiCustomizer
    {
        protected ISettingManager SettingManager;
        protected string ThemeName;

        public ThemeDefaultUiCustomizer(ISettingManager settingManager)
        {
            SettingManager = settingManager;
            ThemeName = AppConsts.ThemeDefault;
        }

        public UiCustomizationSettingsDto GetUiSettings()
        {
            var settings = new UiCustomizationSettingsDto
            {
                BaseSettings = GetDefaultThemeSettingsDto()
            };

            settings.BaseSettings.Theme = ThemeName;
            settings.BaseSettings.Layout.LayoutType = "fluid";
            settings.BaseSettings.Menu.Position = "left";
            settings.BaseSettings.SubHeader.SubheaderSize = 5;
            settings.BaseSettings.SubHeader.TitleStlye = "text-dark font-weight-bold mt-2 mb-2 mr-5";
            settings.BaseSettings.SubHeader.ContainerStyle = "subheader py-2 py-lg-4 subheader-solid";

            settings.IsLeftMenuUsed = true;
            settings.IsTopMenuUsed = false;
            settings.IsTabMenuUsed = false;

            return settings;
        }

        public async Task UpdateUserUiManagementSettingsAsync(UserIdentifier user, ThemeSettingsDto settings)
        {
            await Task.FromResult(1);
            //await SettingManager.ChangeSettingForUserAsync(user, AppSettings.UiManagement.Theme, ThemeName);

            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.Header.DesktopFixedHeader, settings.Header.DesktopFixedHeader.ToString());
            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.Header.MobileFixedHeader, settings.Header.MobileFixedHeader.ToString());
            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.Header.Skin, settings.Header.HeaderSkin);

            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.SubHeader.Fixed, settings.SubHeader.FixedSubHeader.ToString());
            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.SubHeader.Style, settings.SubHeader.SubheaderStyle);

            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.LeftAside.AsideSkin, settings.Menu.AsideSkin);
            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.LeftAside.FixedAside, settings.Menu.FixedAside.ToString());
            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.LeftAside.AllowAsideMinimizing, settings.Menu.AllowAsideMinimizing.ToString());
            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.LeftAside.DefaultMinimizedAside, settings.Menu.DefaultMinimizedAside.ToString());
            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.LeftAside.SubmenuToggle, settings.Menu.SubmenuToggle);
            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.LeftAside.HoverableAside, settings.Menu.HoverableAside.ToString());
            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.SearchActive, settings.Menu.SearchActive.ToString());

            //await ChangeSettingForUserAsync(user, AppSettings.UiManagement.Footer.FixedFooter, settings.Footer.FixedFooter.ToString());
        }

        public async Task UpdateTenantUiManagementSettingsAsync(int tenantId, ThemeSettingsDto settings)
        {
            await Task.FromResult(1);
        }

        public async Task UpdateApplicationUiManagementSettingsAsync(ThemeSettingsDto settings)
        {
            await Task.FromResult(1);
        }

        public ThemeSettingsDto GetHostUiManagementSettings()
        {
            return GetDefaultThemeSettingsDto();
        }

        public ThemeSettingsDto GetTenantUiCustomizationSettings(int tenantId)
        {
            return GetDefaultThemeSettingsDto();
        }

        private ThemeSettingsDto GetDefaultThemeSettingsDto()
        {
            return new ThemeSettingsDto
            {
                Theme = ThemeName,
                Header = new ThemeHeaderSettingsDto
                {
                    DesktopFixedHeader = true,
                    MobileFixedHeader = false,
                    HeaderSkin = "light"
                },
                SubHeader = new ThemeSubHeaderSettingsDto
                {
                    FixedSubHeader = true,
                    SubheaderStyle = "solid"
                },
                Menu = new ThemeMenuSettingsDto
                {
                    AsideSkin = "light",
                    FixedAside = true,
                    AllowAsideMinimizing = true,
                    DefaultMinimizedAside = false,
                    SubmenuToggle = "false",
                    HoverableAside = false,
                    SearchActive = true,
                },
                Footer = new ThemeFooterSettingsDto
                {
                    FixedFooter = false
                }
            };
        }
    }
}
